package com.taxshare.seller.util;


import java.util.Map;

import org.apache.commons.collections4.MapUtils;

import cn.hutool.core.util.IdUtil;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 拼装接口报文 json版本
 * @author: scl
 * @Company: Beijing Holytax Technology Development Co.,Ltd
 * @Date: 2018-10-23
 */
public class InitJsonHelper {

	public static JSONObject commonJson(String serviceid,String async,String nsrsbh,String appid,String sid) {
		JSONObject job = new JSONObject();
		job.put("serviceid",serviceid);
		job.put("nsrsbh",nsrsbh);
		job.put("async",async);
		job.put("appid",appid);
		job.put("sid",sid);
		return job;
	}

	/*
	 *查询绑定授权信息
	 */
	public static String CXJG(String nsrsbh,String appid,String sid) {
		JSONObject job = commonJson("CXJG","true",nsrsbh,appid,sid);
		JSONObject job1 = new JSONObject();
		job.put("input",job1);
		return job.toString().trim();
	}

	/*
	 *检测客户端在线状态
	 */
	public static String JCZXZT(String nsrsbh,String appid,String sid) {
		JSONObject job = commonJson("JCZXZT","true",nsrsbh,appid,sid);
		JSONObject job1 = new JSONObject();
		job.put("input",job1);
		return job.toString().trim();
	}

	/*
	 *当前未开具发票号码
	 */
	public static String HQDQFPDMHM(String nsrsbh,String appid,String sid,String plx, String fplxdm) {
		JSONObject job = commonJson("HQDQFPDMHM","true",nsrsbh,appid,sid);
		JSONObject job1 = new JSONObject();
		job1.put("fplxdm",InvoiceHelper.transFplxdm(plx,fplxdm));
		job.put("input",job1);
		return job.toString().trim();
	}

	/*
	 *智能赋码
	 */
	public static String ZNBM(String serviceId ,String nsrsbh,String appid,String sid,String goodsName) {
		JSONObject job = commonJson(serviceId,"true",nsrsbh,appid,sid);
		JSONObject job1 = new JSONObject();
		job1.put("spmc",goodsName);
		job.put("input",job1);
		return job.toString().trim();
	}


	/*
	 *发票开具
	 */
	public static String GPXXCX(String nsrsbh,String appid,String sid, String fplxdm) {
		JSONObject job = commonJson("GPXXCX","true",nsrsbh,appid,sid);
		JSONObject job1 = new JSONObject();
		job1.put("fplxdm",fplxdm);
		job.put("input",job1);
		return job.toString().trim();
	}

	public static String JKSJCX(String nsrsbh, String appid, String sid, String fplxdm,String plx) {
		JSONObject job = commonJson("JKSJCX","true",nsrsbh,appid,sid);
		JSONObject job1 = new JSONObject();
		job1.put("fplxdm",InvoiceHelper.transFplxdm(plx,fplxdm));
		job.put("input",job1);
		return job.toString().trim();
	}

	public static String WLGPCX(String nsrsbh,String appid) {

		JSONObject job = commonJson("WLGPCX","true",nsrsbh,appid,IdUtil.fastSimpleUUID());
		JSONObject job1 = new JSONObject();
		job1.put("fplxdm","");
		job.put("input",job1);
		return job.toString().trim();
	}

	public static String WLGP(String service,Map<String,Object> paraMap) {
		String taxNo = MapUtils.getString(paraMap, "taxNo", "");
		String appid = MapUtils.getString(paraMap, "appid", "");
		String fplx_dm = MapUtils.getString(paraMap, "fplxdm", "");
		String fpdm = MapUtils.getString(paraMap, "fpdm", "");
		String fphm_q = MapUtils.getString(paraMap, "fphm_q", "");
		String fphm_z = MapUtils.getString(paraMap, "fphm_z", "");
		String fs = MapUtils.getString(paraMap, "fs", "");
		JSONObject job = commonJson(service,"true",taxNo,appid,IdUtil.fastSimpleUUID());
		JSONObject job1 = new JSONObject();
		JSONArray gpxx = new JSONArray();
		JSONObject  ffxx = new JSONObject();
		//TODO  Ukey需要再做判断
		ffxx.put("fplx_dm",fplx_dm);
		ffxx.put("fpdm",fpdm);
		ffxx.put("fphm_q",fphm_q);
		ffxx.put("fphm_z",fphm_z);
		ffxx.put("fs",fs);
		gpxx.add(ffxx);
		job1.put("gpxx",gpxx);
		job1.put("fplxdm","");
		job.put("input",job1);
		return job.toString().trim();

	}
}
